package com.kczd.fragment;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kczd.activity.AboutSoftwareActivity;
import com.kczd.activity.DriverActivity;
import com.kczd.activity.GochenGoActivity;
import com.kczd.activity.HeadsetActivity;
import com.kczd.activity.ServiceActivity;
import com.kczd.activity.SetActivity;
import com.kczd.activity.WalletActivity;
import com.kczd.activity.WeActivity;
import com.kczd.client.R;
import com.kczd.entity.Driver;
import com.kczd.util.Common;
import com.kczd.util.ObjectSaveUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import static com.kczd.activity.MainActivity.viewPager;


/**
 * 我的
 */

public class MyFragment extends Fragment implements View.OnClickListener {

    private View view;
    private LinearLayout ll_wallet;//我的钱包,
    private LinearLayout ll_driver;//司机加盟
    private LinearLayout ll_personal;//头像以及详细信息编辑
    private LinearLayout ll_xingcheng;//头像以及详细信息编辑
    private LinearLayout ll_kefu;//头像以及详细信息编辑
    private LinearLayout ll_we;//关于我们
    private LinearLayout ll_software;//软件
    private ImageView    iv_set;//设置

    private ImageView  iv_head;
    private TextView   tv_name;
    private TextView   tv_selfsign;
    private TextView   tv_telephone;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         view = inflater.inflate(R.layout.mine_fragment, container, false);
        setView();
        return view;
    }

    private void setView() {
        ll_wallet=(LinearLayout) view.findViewById(R.id.ll_qianbao);
        ll_driver=(LinearLayout)view.findViewById(R.id.ll_driver);
        ll_personal= (LinearLayout) view.findViewById(R.id.ll_personal);
        ll_xingcheng= (LinearLayout) view.findViewById(R.id.ll_xingcheng);
        ll_we=(LinearLayout) view.findViewById(R.id.ll_we);
        ll_kefu= (LinearLayout) view.findViewById(R.id.ll_kefu);
        ll_software=(LinearLayout) view.findViewById(R.id.ll_software);
        iv_set=(ImageView) view.findViewById(R.id.iv_set);

        iv_head=(ImageView) view.findViewById(R.id.iv_head);
        tv_name=(TextView) view.findViewById(R.id.tv_name);
        tv_selfsign=(TextView) view.findViewById(R.id.tv_selfsign);
        tv_telephone=(TextView) view.findViewById(R.id.tv_telephone);

        ll_driver.setOnClickListener(this);
        ll_wallet.setOnClickListener(this);
        iv_set.setOnClickListener(this);
        ll_personal.setOnClickListener(this);
        ll_xingcheng.setOnClickListener(this);
        ll_software.setOnClickListener(this);
        ll_kefu.setOnClickListener(this);
        ll_we.setOnClickListener(this);

        setUserInfo();
    }

    public void setUserInfo(){
        String uImage ="http://www.dafuw.com/itf/uploadfile/"+Common.user.getDriver_img();
        Log.e("leehuan",uImage);
        //显示图片的配置
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.img_loading)
                .showImageOnFail(R.mipmap.img_fail)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build();
        ImageLoader.getInstance().displayImage(uImage, iv_head, options);
        tv_name.setText(Common.user.getUsername().contains("null")?"":Common.user.getUsername());
        tv_selfsign.setText(Common.user.getSelf_sign().contains("null")?"":Common.user.getSelf_sign());
        tv_telephone.setText(Common.user.getTel().contains("null")?"":Common.user.getTel());
    }
    @Override
    public void onResume() {
        super.onResume();
        setUserInfo();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.iv_set:
                startActivity(new Intent(getActivity(), SetActivity.class));//设置页面
                break;
            case R.id.ll_personal:
                startActivity(new Intent(getActivity(), HeadsetActivity.class));//头像以及详细信息编辑
                break;

            case R.id.ll_qianbao:
                startActivity(new Intent(getActivity(), WalletActivity.class));//我的钱包
                break;
            case R.id.ll_xingcheng:
                startActivity(new Intent(getActivity(), GochenGoActivity.class));//我的行程
                break;
            case R.id.ll_driver:
                startActivity(new Intent(getActivity(), DriverActivity.class));//司机加盟
                break;
            case R.id.ll_kefu:
                startActivity(new Intent(getActivity(), ServiceActivity.class));//客服
                break;
            case R.id.ll_we:
                startActivity(new Intent(getActivity(), WeActivity.class));//关于我们
                break;
            case R.id.ll_software:
                startActivity(new Intent(getActivity(), AboutSoftwareActivity.class));//关于软件
                break;
            default:
                break;
        }
    }
}
